package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @Author atguigu-mqx
 * @Description TODO
 * @Date 2023/7/25 14:41
 * @Version 1.0
 */
@Configuration
public class DelayedMqConfig {
    //  声明变量
    public static final String exchange_delay = "exchange.delay";
    public static final String routing_delay = "routing.delay";
    public static final String queue_delay_1 = "queue.delay.1";

    @Bean
    public CustomExchange delayExchange(){
        //  延迟插件实现延迟消息，你需要在内部配置连接方式
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-delayed-type","direct");
        return new CustomExchange(exchange_delay,"x-delayed-message",true,false,map);
    }

    @Bean
    public Queue delayQueue(){
        return new Queue(queue_delay_1,true,false,false);
    }

    @Bean
    public Binding delayBinding(){
        //  因为创建交换机不同！
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(routing_delay).noargs();
    }
}
